<%-- 
    Document   : delete_post
    Created on : 2 Jun, 2012, 2:57:35 PM
    Author     : bharat
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="./css/maincss.css">
        <link rel="stylesheet" type="text/css" href="./css/myaccountcss.css">
        <title>Online College Magazine</title>
    </head>
    <body>
        <div class="container">
            <div class="header">
                ONLINE COLLEGE MAGAZINE
            </div>
            <div class="navigation_menu">
                <%@include file="navigationmenu.jsp"%>
            </div>

            <div class="posts">
                <%@include file="display_posts.jsp" %>
            </div>
            <div class="profile">
                <%@include file="display_profile.jsp" %>
            </div>
            <div class="display_post">


                <%

                    String username1 = (String) session.getAttribute("usr");
                    String pid_ = request.getParameter("pid");
                    
                    Connection con3 = null;
                    PreparedStatement pstmt3 = null;
                    PreparedStatement pstmt4 = null;
                    ResultSet rs3 = null;
//                    con3.setAutoCommit(false);

                    try {
                        Class.forName("oracle.jdbc.driver.OracleDriver");
                        con3 = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "aksh", "aksh");

                        pstmt4 = con3.prepareStatement("delete from posts where pid=?");
                        pstmt4.setString(1, pid_);
                        pstmt4.executeUpdate();
                        con3.commit();

                        pstmt3 = con3.prepareStatement("select subject, post from posts where pid=?");
                        pstmt3.setString(1, pid_);
                        rs3 = pstmt3.executeQuery();
                        if (rs3.next()) {
                %>

                <table boder="2" cellpadding="5">
                    <tr><th>
                            <%
                                out.println(rs3.getString(1));
                            %>

                        </th></tr><tr><td><p>

                                <%
                                    out.println(rs3.getString(2));
                                %>

                            </p></td></tr></table>

                <%
                        }
                    } catch (Exception e) {
                        con3.rollback();
                        e.printStackTrace();
                        response.sendError(504, e.getMessage());
                    } finally {
                        if (rs3 != null) {
                            try {
                                rs3.close();
                            } catch (Exception e) {
                                response.sendError(502, e.getMessage());
                            }
                        }
                        if (pstmt3 != null) {
                            try {
                                pstmt3.close();
                            } catch (Exception e) {
                                response.sendError(502, e.getMessage());
                            }
                        }
                        if (con3 != null) {
                            try {
                                con3.close();
                            } catch (Exception e) {
                                response.sendError(502, e.getMessage());
                            }
                        }
                    }
                %>

            </div>                         
            <div class="footer">
                FOOTER
            </div>
        </div>
    </body>
</html>
